// See https://github.com/Jias/natty-fetch for more details.
import { monStorage, Storage } from 'clientConfig/util/StoreData';
let nattyFetch = require('natty-fetch');
nattyFetch.setGlobal({
    // 配置整个项目所有接口的参数中都包含`session`字段
    query: {
        session: monStorage.get('user.session')
    }
});
const context = nattyFetch.context({
    mockUrlPrefix: '/mock/',
    urlPrefix: '/its/', // window.isBp ?  '//10.100.254.124/proxy_id%7BEAF256F4-548C-418F-809E-8B0E80203C5C%7D/proxy_ipxxx/its/' : '//xxx/its/'
    header: {
        'Content-Type': 'application/json;charset=utf-8'
    },
    mock: false,
    withCredentials: false,
    traditional: true,
    urlStamp: false,
    urlMark: false,
    timeout: 0,
    fit: function (response) {
        let ret = {
            success: response.errcode == 0 ? true : false
        };
        if (ret.success) {
            ret.content = response.content ? response.content : response.errmsg;
            if (response.userlist) {
                ret.content = response.userlist
            }
        } else {
            ret.error = {
                message: response.errmsg,
                errcode: response.errcode
            }
        }
        return ret;
    }
});

context.create('Module', {
    getListInfo: {
        mockUrl: 'query/getListInfo.json'
    },
    getListedInfo: {
        mockUrl: 'query/getListedInfo.json'
    },
    getDetailListInfo: {
        mockUrl: 'query/getDetailListInfo.json'
    },
    getListsingle: {
        mockUrl: 'query/getListsingle.json'
    },
    getListnotice: {
        mockUrl: 'query/getListnotice.json'
    },

});
context.create('Approval', {
    send_approval: {
        url: 'send_approval',
        method: 'POST',
        data: {}
    },
    get_approval_list: {
        mockUrl: 'query/getListInfo.json',
        url: 'get_approval_list'
    },
    update_approval: {
        mockUrl: 'query/getListInfo.json',
        url: 'update_approval',
        method: 'POST'
    },
    get_approval_detail: {
        mockUrl: 'get_approval_detail',
        url: 'get_approval_detail'
    },
    get_achievements_lists: {
        url: "get_achievements_lists"
    },
    get_org: {
        url: "get_org"
    }
});
context.create('Proj', {
    get_sigleProj_process: {
        mockUrl: 'query/getListInfo.json',
        url: 'get_sigleProj_process'
    },
    get_workplan_overview: {
        mockUrl: 'query/getListInfo.json',
        url: 'get_workplan_overview'
    },
    get_payment_overview: {
        mockUrl: 'query/getListInfo.json',
        url: 'get_payment_overview'
    },
    get_projs_fault: {
        mockUrl: 'get_projs_fault',
        url: 'get_projs_fault'
    },
});
context.create('File', {
    upload_file: {
        header: {
            'Content-Type': 'multipart/form-data'
        },
        mockUrl: 'query/getListInfo.json',
        url: 'upload_file',
        method: 'POST'
    },
    delete_file: {
        mockUrl: 'query/getListInfo.json',
        url: 'delete_file',
    },
    get_filelists: {
        url: "get_filelists"
    },
    download_file: {
        url: "download_file"
    },
    create_file_path: {
        url: 'create_file_path'
    },
    delete_file_path: {
        url: 'delete_file_path'
    },
    rename_file_path: {
        url: 'rename_file_path'
    },
    get_file: {
        url: 'get_file'
    },
    update_file_info: {
        url: 'update_file_info'
    }

});
context.create('Notice', {
    send_notice: {
        mockUrl: 'query/getListInfo.json',
        url: 'send_notice',
        method: 'POST'
    },
    get_notice_lists: {
        mockUrl: 'query/getListInfo.json',
        url: 'get_notice_lists'
    },
    update_notice: {
        url: "update_notice",
        method: 'POST'
    },
    delete_notice: {
        url: "delete_notice"
    }
});
context.create('Permission', {
    bind_participant: {
        url: 'bind_participant',
    },
    unbind_participant: {
        url: 'unbind_participant'
    },
    bind_file_permission: {
        url: 'bind_file_permission'
    },
    unbind_file_permission: {
        url: 'unbind_file_permission'
    }
});
context.create('Table', {
    get_table_data: {
        url: 'get_table_data',
    }
});
module.exports = context.api;
